<template>
  <el-dialog title="详情" :visible.sync="visiable" width="50%" :before-close="handleClose">
    <el-form ref="formData" :model="formData" label-width="100px"  >
      <el-form-item label="歌手姓名:" prop="singerName">
        <el-input v-model="formData.singerName" readonly></el-input>
      </el-form-item>
      <el-form-item label="头像">
        <img :src="formData.singerAvatar" style="width:178px; height:178px; display: block" />
      </el-form-item>
      <el-form-item label="性别" prop="singerSex">
        <el-radio-group v-model="formData.singerSex" disabled>
          <el-radio :label="1">男</el-radio>
          <el-radio :label="0">女</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="年龄:" prop="singerAge">
        <el-input v-model="formData.singerAge" readonly></el-input>
      </el-form-item>
      <el-form-item label="地址:" prop="singerAddr">
        <el-input v-model="formData.singerAddr" readonly></el-input>
      </el-form-item>
      <el-form-item label="简介:" prop="singerDescription">
        <textarea readonly v-model="formData.singerDescription" style="width: 815px;height: 60px;"></textarea>
      </el-form-item>
    </el-form>
  </el-dialog>
</template>

<script>
import {dateFormat} from "@/utils/date";
import musicApi from '@/api/music';
export default {
  props:{
    id: null,  // 歌手id
    visiable:{  // 弹出窗口
      type:Boolean,
      default:false
    },
    remoteClose: Function, //用于关闭窗口
  },

  watch: {
    // 监听visiable的变化 将改变之后的值传入
    visiable(val) {
      if(val) {
        this.fetchData();
      }
    },
  },

  data() {
    return {
      formData: {}
    }
  },

  methods: {
    // 查询歌手详情
    fetchData() {
      musicApi.getSingerById(this.id).then(response => {
        if (response.code === 200) {
          this.formData = response.data;
        }
      })
    },

    // 关闭窗口
    handleClose() {
      // 调用父组件的方法关闭窗口
      this.remoteClose();
    },

    // 格式化日期
    getFormat(date){
      return dateFormat(date);
    },
  }
}
</script>

<style scoped>

</style>
